package edu.hawaii.ics499;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class DataPreviewActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.previewdata);
        
        DatabaseHelper db = new DatabaseHelper(this);
        SQLiteDatabase qdb = db.getReadableDatabase();
        
        TextView text2 = (TextView) findViewById(R.id.text2);
        Button cancelBack = (Button) findViewById(R.id.cancel_back);
        
        Cursor cursor = qdb.rawQuery("SELECT * from accelerometer", null);
        
        text2.setText("Data: \n");
        
        cursor.moveToFirst();
        while(!cursor.isAfterLast()) {
          text2.append(cursor.getFloat(1) + "\t" + cursor.getString(2) + "\n");
          cursor.moveToNext(); 
        }
        
        cancelBack.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            finish();
          }
        });
    }
}